i have an array which looks like this:
[
"[-33.85812364015231, 151.19984484776273]",
"[-33.85812364015231, 151.19984484776273]",
"[-33.87137985320215, 151.19263084032974]"
]
how do i get the objects out of their strings. Parsing them into floats removed the second value in the object. Trying to replace( ' " ', " ") the speech marks doesn't work.
thanks
You have an array of JSON strings.
To get an array of arrays of numbers, use
const parsedArr = arr.map(JSON.parse);
and then parsedArray[someNum] will give you a coordinate array of numbers, like [-33.85812364015231, 151.19984484776273].
this way :
without unnecessarily recreating a new array (as does the array.map() method )
const myArray =
[ "[-33.85812364015231, 151.19984484776273]"
, "[-33.85812364015231, 151.19984484776273]"
, "[-33.87137985320215, 151.19263084032974]"
]
myArray.forEach((row,i,Arr) => Arr[i] = JSON.parse(row) )
console.log( myArray )